﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Text.RegularExpressions;
using PmSoft.Utilities;

namespace PmSoft
{
    /// <summary>
    /// string扩展方法
    /// </summary>
    public static class StringExtensions
    {
        public static bool IsNullOrWhiteSpace(this string input)
        {
            return string.IsNullOrWhiteSpace(input);
        }

        public static bool IsNotNullAndWhiteSpace(this string input)
        {
            return !string.IsNullOrWhiteSpace(input);
        }


        public static bool IsNullOrEmpty(this string input)
        {
            return string.IsNullOrEmpty(input);
        }

        public static string ToFilePath(this string path)
        {
            return Path.Combine(path.Split(new char[] { '/', '\\' }, StringSplitOptions.RemoveEmptyEntries));
        }

        public static string ShowNotAvailable(this string? input, string text = "N/A")
        {
            if (string.IsNullOrWhiteSpace(input))
                return text;
            return input;
        }

        public static string ToSingleLine(this string text)
        {
            if (string.IsNullOrEmpty(text))
                return text;
            return Regex.Replace(text, "[\f\n\r\t\v]", "");
        }

    }
}
